@extends('layouts.admin')

@section('title', '店铺管理')
@section('scripts')
    <script src="{{asset('DatePicker/WdatePicker.js')}}" type="text/javascript"></script>
@stop

@section('content')
    <ol class="breadcrumb">
        <li class="breadcrumb-item">后台管理</li>
        <li class="breadcrumb-item">店铺管理</li>
        <li class="breadcrumb-item active">店铺列表</li>
    </ol>
    <div class="search-container">
        <form method="get" id="searchFrom">
            <div class="row">
                <div class="cell">
                    <div class="label">店铺名称:</div>
                    <div class="field"><input title="" type="text" class="form-control w200" name="shop_name" value="{{$shop_name}}"></div>
                </div>
                <div class="cell">
                    <div class="label">卖家账号:</div>
                    <div class="field"><input title="" type="text" class="form-control w200" name="username" value="{{$username}}"></div>
                </div>
                <div class="cell">
                    <div class="label">联系电话:</div>
                    <div class="field"><input title="" type="text" class="form-control w200" name="phone" value="{{$phone}}"></div>
                </div>
            </div>
            <div class="row">
                <div class="cell">
                    <div class="label">店铺状态:</div>
                    <div class="field">
                        <select title="" class="form-control w200" name="shop_status">
                            <option value="0">全部</option>
                            <option value="OPEN"@if($shop_status=='OPEN') selected="selected"@endif>营业中</option>
                            <option value="CLOSE"@if($shop_status=='CLOSE') selected="selected"@endif>已关闭</option>
                        </select>
                    </div>
                </div>
                <div class="cell" style="width: auto;">
                    <div class="label">开店时间:</div>
                    <div class="field">
                        <label><input title="" type="text" class="form-control w100" name="time_begin" onclick="WdatePicker()" value="{{$time_begin}}"></label>
                        <label class="seperator">-</label>
                        <label><input title="" type="text" class="form-control w100" name="time_end" onclick="WdatePicker()" value="{{$time_end}}"></label>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="cell">
                    <div class="label"></div>
                    <div class="field">
                        <label><button type="button" class="btn btn-primary" id="btn-search">搜索店铺</button></label>
                        <label><button type="button" class="btn btn-default" id="btn-export">批量导出</button></label>
                    </div>
                </div>
            </div>
        </form>
    </div>

    <div class="tabs-container">
        <ul class="tabs">
            <li role="presentation" class="tab-item">
                <a href="{{admin_url('shop?tab=all')}}" class="tab-link{{$tab=='all' ? ' active' : ''}}">所有店铺</a>
            </li>
            <li role="presentation" class="tab-item">
                <a href="{{admin_url('shop?tab=open')}}" class="tab-link{{$tab=='open' ? ' active' : ''}}">营业中</a>
            </li>
            <li role="presentation" class="tab-item">
                <a href="{{admin_url('shop?tab=closed')}}" class="tab-link{{$tab=='closed' ? ' active' : ''}}">已关闭</a>
            </li>
        </ul>
    </div>

    <div class="content-div">
        <form method="post" id="listForm" autocomplete="off">
            @csrf
            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="listtable">
                <thead>
                <tr>
                    <th width="20"><input title="" type="checkbox" class="checkmark" data-action="checkall"></th>
                    <th width="70">LOGO</th>
                    <th>店铺名称</th>
                    <th>掌柜</th>
                    <th>店铺认证</th>
                    <th>店铺状态</th>
                    <th width="80">营业状态</th>
                    <th width="120">开店时间</th>
                    <th width="60">选项</th>
                </tr>
                </thead>
                <tbody>
                @foreach($shops as $shop)
                <tr>
                    <td><input title="" type="checkbox" class="checkmark" name="shops[]" value="{{$shop['shop_id']}}"></td>
                    <td>
                        <a href="{{shop_url($shop['shop_id'])}}" target="_blank">
                            <div class="bg-cover" style="width: 50px; height: 50px; background-image: url({{image_url($shop['logo'])}})"></div>
                        </a>
                    </td>
                    <td><a href="{{shop_url($shop['shop_id'])}}" target="_blank">{{$shop['shop_name']}}</a></td>
                    <td>{{$shop['user']['username']}}</td>
                    <td>
                        @if($shop['auth_status'])
                            <span style="color: #4cae4c;">已认证</span>
                        @else
                            <span style="color: #ff0000">未认证</span>
                        @endif
                    </td>
                    <td>
                        @if($shop['bond_status'])
                            <span style="color: #4cae4c;">已缴纳保证金</span>
                        @else
                            <span style="color: #ff0000">未缴纳保证金</span>
                        @endif
                    </td>
                    <td>
                        @if($shop['closed'])
                            <span style="color: #ff0000">已关闭</span>
                        @else
                            <span style="color: #4cae4c;">营业中</span>
                        @endif
                    </td>
                    <td>{{@date('Y年m月d日', $shop['created_at'])}}</td>
                    <td><a href="{{admin_url('shop/edit?shop_id='.$shop['shop_id'])}}">编辑</a></td>
                </tr>
                @endforeach
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="20">
                        <div class="float-right">{!! $pagination !!}</div>
                        <div class="btn-group-sm">
                            <label class="form-check-label"><input type="checkbox" class="checkmark" data-action="checkall"> 全选</label>
                            <button type="button" class="btn btn-default btn-action" disabled="disabled" id="batchdelete">批量删除</button>
                            <button type="button" class="btn btn-default btn-action" disabled="disabled" id="batchclose">批量关闭</button>
                            <button type="button" class="btn btn-default btn-action" disabled="disabled" id="batchopen">批量开启</button>
                        </div>
                    </td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
    <iframe id="expore_frame" style="display: none;"></iframe>
    <script type="text/javascript">
        $(function () {
            $(document).on('click', function () {
                if ($(".checkmark:checked").length > 0) {
                    $(".btn-action").enable();
                }else {
                    $(".btn-action").disable();
                }
            });

            $("#batchdelete").on('click', function () {
                DSXUI.showConfirm('确认要删除所选店铺吗?', function () {
                    $("#listForm").ajaxSubmit({
                        url:'{{admin_url('shop/batchdelete')}}',
                        beforeSend:DSXUI.showSpinner,
                        success:function (response) {
                            setTimeout(function () {
                                DSXUI.hideSpinner();
                                DSXUtil.reFresh();
                            }, 500);
                        }
                    });
                });
            });

            $("#batchclose").on('click', function () {
                DSXUI.showConfirm('确认要关闭所选店铺吗?', function () {
                    $("#listForm").ajaxSubmit({
                        url:'{{admin_url('shop/batchclose')}}',
                        beforeSend:DSXUI.showSpinner,
                        success:function (response) {
                            setTimeout(function () {
                                DSXUI.hideSpinner();
                                DSXUtil.reFresh();
                            }, 500);
                        }
                    });
                });
            });

            $("#batchopen").on('click', function () {
                $("#listForm").ajaxSubmit({
                    url:'{{admin_url('shop/batchopen')}}',
                    beforeSend:DSXUI.showSpinner,
                    success:function (response) {
                        setTimeout(function () {
                            DSXUI.hideSpinner();
                            DSXUtil.reFresh();
                        }, 500);
                    }
                });
            });

            $("#btn-search").on('click', function () {
                $("#J_a").val('itemlist');
                $("#searchFrom").submit();
            });
        });
    </script>
@stop
